package org.xxpay.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xxpay.core.entity.SysCityCode;
import org.xxpay.core.entity.SysCityCodeExample;
import org.xxpay.core.service.ISysCityCodeService;
import org.xxpay.service.dao.mapper.SysCityCodeMapper;

import java.util.List;


@Service
public class SysCityCodeServiceImpl implements ISysCityCodeService {

    @Autowired
    SysCityCodeMapper sysCityCodeMapper;

    @Override
    public int add(SysCityCode sysCityCode) {
        return sysCityCodeMapper.insertSelective(sysCityCode);
    }

    @Override
    public int update(SysCityCode sysCityCode) {
        return sysCityCodeMapper.updateByPrimaryKeySelective(sysCityCode);
    }

    @Override
    public SysCityCode find(SysCityCode sysCityCode) {
        return sysCityCodeMapper.selectByPrimaryKey(sysCityCode.getCityCode());
    }

    @Override
    public List<SysCityCode> select(SysCityCode sysCityCode) {
        SysCityCodeExample example = new SysCityCodeExample();
        SysCityCodeExample.Criteria criteria = example.createCriteria();
        setCriteria(criteria, sysCityCode);
        return sysCityCodeMapper.selectByExample(example);
    }

    void setCriteria(SysCityCodeExample.Criteria criteria, SysCityCode sysCityCode) {
        if(sysCityCode != null) {
            if(sysCityCode.getCityCode() != null) criteria.andCityCodeEqualTo(sysCityCode.getCityCode());
            if(sysCityCode.getProvinceCode() != null) criteria.andProvinceCodeEqualTo(sysCityCode.getProvinceCode());
        }
    }
}
